from fastapi import APIRouter,Depends
from autotest.utils.response.http_response import partner_success
from autotest.schemas.api.data_factory import ApiQuery, DfApiIn, DfApiId, DfApiQuery,DfApiListQuery
from autotest.services.api.data_factory import DfApiService
from autotest.db.db_depends import get_db_connection,get_db_connection01,DataBase

router = APIRouter()


@router.post('/list', description="获取造数场景列表")
async def api_list(params: DfApiListQuery):
    result = await DfApiService.list(params)
    return partner_success(result)


@router.post('/detail', description="获取造数场景详情")
async def api_detail(params: DfApiQuery):
    result = await DfApiService.detail(params)
    return partner_success(result)


@router.post('/saveOrUpdate', description="更新保存接口")
async def save_or_update(params: DfApiIn):
    case_info = await DfApiService.save_or_update(params)
    return partner_success(case_info)


@router.post('/deleted', description="删除接口")
async def deleted(params: DfApiId):
    """
    接口删除
    :return:
    """
    data = await DfApiService.deleted(params.id)
    return partner_success(data)


@router.get('/dependTest', description="依赖注入，用于多db场景")
async def dependTest(
        # params: DataBase,
        db=Depends(get_db_connection01)
):

    # data = await DfApiService.dependsTest(db)
    # data = await DfApiService.dependsTestAdd(db)
    data = await DfApiService.dependsTestUpdate(db)
    return partner_success(data)